<template>
	<view class="page">
		<view class="icon-title">{{loginTitleTxt}}</view>
		<view class="login-icon">
			<view class="icon iconfont icon-weidenglutouxiang" style="color: #2AB795;font-size: 100px;line-height: 300upx;"></view>
		</view>
		<view class="user-pass">
			<view class="login-box login-name">
				<view class="user-icon iconfont icon-weidenglu" style="color: gray;font-size: 30px;"></view>
				<input class="login-input" v-model="params.phoneNo" type="text" placeholder="手机号码" value="" />
			</view>
			<view class="login-box login-pass">
				<view class="pass-icon iconfont icon-mima" style="color: gray;font-size: 30px;"></view>
				<input class="login-input" v-model="params.code" type="text" placeholder="验证码" value="" />
				<button type="primary" :disabled="sendCodeKey" class="verify">发送验证码</button>
			</view>
			<view class="forget">
				<view class="forget-pass">忘记密码</view>
			</view>
		</view>
		
		<button class="login-button" :disabled="submitBtnDis || submitBtnDisKey" @tap="login">登录</button>
		<view class="regist">注册账号</view>
		<view class="line-box">
			<view class="line-out">
				<view class="line"></view>
			</view>
			<view class="or-out">
				<view class="line-or">第三方登录</view>
			</view>
			<view class="line-out">
				<view class="line"></view>
			</view>
		</view>
		<view class="button-group">
			<button type="primary" class="third-button" :style="button.icon" v-for="(button, ind) in buttons" :key="ind">{{button.title}}</button>			
		<view class="version">
			<view class="iconfont icon-banquan">{{copyrightTxt}}</view>
		</view>
		</view>
	</view>
</template>

<script>
	import {mapState, mapMutations, mapGetters, mapActions} from 'vuex';
	import graceChecker from '@/common/graceChecker.js';
	import formRuleConfig from '@/config/formRule.config.js';
	
	export default {
		data() {
			return {
				buttons: [{icon: 'background-image: url("../../static/mall/wx.png");',title: '微信账号登录'},
					{icon: 'background-image: url("../../static/mall/qq.png");',title: '微博账号登录'},
					{icon: 'background-image: url("../../static/mall/wb.png");',title: 'QQ账号登录'}],
				loginTitleTxt: this.$mConfig.loginTitleTxt,
				copyrightTxt: this.$mConfig.copyrightTxt,
				params: {phoneNo:"", code:"" },
				reqBody: {},
				submitBtnDis: false
			}
		},
		computed: {
			sendCodeKey(){
				let checkParams = {};
				checkParams["phoneNo"] = this.params.phoneNo;
				let res = graceChecker.check(checkParams, formRuleConfig.sendCodeRule);
				console.log(this.params.phoneNo + "=====" + res)
				return !res;
			},
			submitBtnDisKey(){
				let checkParams = {};
				checkParams["phoneNo"] = this.params.phoneNo;
				checkParams["code"] = this.params.code;
				let res = graceChecker.check(checkParams, formRuleConfig.loginRule);
				return !res;
			}
		},
		methods: {
			// 登录方法
			async login(){
				this.reqBody["phone"] = this.params["phoneNo"];
				this.reqBody["code"] = this.params["code"];
				uni.request({
					url: this.serverUrl + '/member/login',
					data: this.reqBody,
					method: 'POST',
					success: (res) => {
						if(res.data.resultCode == 0){
							var userInfo = res.data.resultData;
							// 保存用户信息到全局的缓存中
							uni.setStorageSync("globalUser", userInfo);
							// 切换页面跳转，使用tab切换的ap
							uni.switchTab({
								url:'../user/user'
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	@import url("login.css");
	@import url("../../static/iconfont/iconfont.css");
</style>
